<template>
  <div class="wrapper">
    <!-- 头部布局 -->
    <div class="header-wrapper">
      <div
        class="header-box"
        v-for="item in detailsList"
        :key="item.category_id"
      >
        <div class="title">{{ item.product_name }}</div>
        <ul>
          <li>概述</li>
          <li>参数</li>
          <li>商品评价</li>
        </ul>
      </div>
    </div>
    <!-- 中间 -->
    <div
      class="content-wrapper"
      v-for="item in detailsList"
      :key="item.category_id"
    >
      <!-- 轮播图  -->
      <div class="left-wrapper">
        <el-carousel height="560px">
          <el-carousel-item v-for="item in PictureList" :key="item.id">
            <img
              :src="'http://101.132.181.9:3000/' + item.product_picture"
              alt=""
            />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="right-wrapper">
        <div class="title">{{ item.product_name }}</div>
        <div class="zi">
          {{ item.product_intro }}
        </div>
        <div class="shop">小米自营</div>
        <div class="price">
          {{ item.product_selling_price }}元
          <span
            class="del"
            v-show="item.product_price !== item.product_selling_price"
            >{{ item.product_price }}元</span
          >
        </div>
        <div class="goods">
          <div class="top">
            {{ item.product_name }}
            <p>
              <span>{{ item.product_selling_price }}元</span>
              <span
                class="del"
                v-show="item.product_price !== item.product_selling_price"
                >{{ item.product_price }}元</span
              >
            </p>
          </div>
          <div class="bottom">总价:{{ item.product_selling_price }}元</div>
        </div>
        <div class="button">
          <el-button class="jia" @click="getAddShoPCart(item.product_id)"
            >加入购物车</el-button
          >
          <el-button class="love" @click="getAddCollect(item.product_id)"
            >喜欢</el-button
          >
        </div>
        <div class="footer">
          <ul>
            <li>
              <i class="el-icon-circle-check"></i>
              小米自营
            </li>
            <li>
              <i class="el-icon-circle-check"></i>
              小米发货
            </li>
            <li>
              <i class="el-icon-circle-check"></i>
              100%7天无理由退货
            </li>
            <li>
              <i class="el-icon-circle-check"></i>
              100%7天价格保护
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { detailsId, PictureId, AddShoPCart, AddCollect } from "@/api/details";
export default {
  name: "details",
  data() {
    return {
      parameter: "",
      detailsList: [],
      PictureList: [],
      userId: this.$store.state.users.user_id,
    };
  },
  created() {
    this.getparameter();
    this.getList();
    this.getPicture(); //轮播图
  },
  methods: {
    //地址栏中找到参数名为type的值
    getparameter() {
      this.parameter = this.$route.query.type;
    },
    /**
     * 添加收藏
     */
    async getAddCollect(pid) {
      const res = await AddCollect({
        user_id: this.userId,
        product_id: pid,
      });
      console.log(res);
      if (
        res.data.code == "001" ||
        res.data.code == "002" ||
        res.data.code == "003"
      ) {
        this.$notify.success({
          title: "成功",
          message: res.data.msg,
          showClose: true,
        });
      }
    },
    /**
     * 添加 购物车
     */
    async getAddShoPCart(pid) {
      const res = await AddShoPCart({
        user_id: this.userId,
        product_id: pid,
      });
      console.log(res);
      if (
        res.data.code == "001" ||
        res.data.code == "002" ||
        res.data.code == "003"
      ) {
        this.$notify.success({
          title: "成功",
          message: res.data.msg,
          showClose: true,
        });
      }
    },
    /**6
     * 渲染数据
     */
    async getList() {
      const res = await detailsId({ productID: this.parameter });
      console.log(res, "11");
      if (res.data.code == "001") {
        this.detailsList = res.data.Product;
      }
    },
    /**
     * 渲染轮播图
     */
    async getPicture() {
      const res = await PictureId({ productID: this.parameter });
      console.log(res, "22");
      if (res.data.code == "001") {
        this.PictureList = res.data.ProductPicture;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
  height: 100%;
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  .header-wrapper {
    width: 100%;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 5px 5px rgb(0 0 0 / 7%);
    display: flex;
    justify-content: center;
    .header-box {
      width: 1225px;
      display: flex;
      justify-content: space-between;
      .title {
        height: 64px;
        line-height: 64px;
        font-size: 18px;
        font-weight: 400;
        color: #212121;
      }
      ul {
        display: flex;
        li {
          width: 80px;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 14px;
          color: #616161;
        }
        &:hover li {
          color: #ff6700;
        }
      }
    }
  }
  .content-wrapper {
    width: 1225px;
    // background: red;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    .left-wrapper {
      width: 560px;
      img {
        width: 100%;
      }
    }
    .right-wrapper {
      width: 650px;
      height: 100%;
      //   background: #78685d;
      padding: 20px;
      .title {
        height: 30px;
        line-height: 30px;
        font-size: 24px;
        font-weight: 400;
        color: #212121;
      }
      .zi {
        color: #b0b0b0;
        padding-top: 10px;
        font-size: 18px;
        line-height: 24px;
      }
      .shop {
        color: #ff6700;
        padding-top: 20px;
        font-size: 15px;
      }
      .price {
        display: block;
        font-size: 20px;
        color: #ff6700;
        border-bottom: 1px solid #e0e0e0;
        padding: 25px 0 25px;
        .del {
          margin-left: 0.5em;
          color: #b0b0b0;
          text-decoration: line-through;
        }
      }
      .goods {
        background: #f9f9fa;
        padding: 30px 60px;
        margin: 50px 0 50px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .top {
          display: flex;
          justify-content: space-between;
          color: #616161;
          font-size: 17px;
          line-height: 30px;
          span {
            font-size: 17px;
          }
          .del {
            margin-left: 0.5em;
            color: #b0b0b0;
            text-decoration: line-through;
          }
        }
        .bottom {
          color: #ff6700;
          font-size: 24px;
          padding-top: 20px;
        }
      }
      .button {
        height: 55px;
        margin: 10px 0 20px 0;
        display: flex;
        .el-button {
          height: 55px;
          font-size: 16px;
          color: #fff;
          border: none;
        }
        .jia {
          width: 340px;
          background-color: #ff6700;
        }
        .love {
          width: 260px;
          margin-left: 40px;
          background-color: #b0b0b0;
        }
      }
      .footer {
        height: 50px;
        ul {
          height: 100%;
          width: 100%;
          display: flex;
          justify-content: flex-start;
          li {
            margin-right: 25px;
            display: flex;
            justify-content: center;
            color: #b0b0b0;
            font-size: 15px;
          }
        }
      }
    }
  }
}
</style>